package com.plian.system.service.im.impl;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.plian.system.entity.im.FundProjectAmountDetail;
import com.plian.system.mapper.im.FundProjectAmountDetailMapper;
import com.plian.system.service.im.IFundProjectAmountDetailService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 服务实现类
 *
 * @author
 * @since 2022-11-30
 */
@Slf4j
@Service
@AllArgsConstructor
public class FundProjectAmountDetailServiceImpl extends ServiceImpl<FundProjectAmountDetailMapper, FundProjectAmountDetail> implements IFundProjectAmountDetailService {


    @Override
    public boolean removeByBaseId(Long baseId) {
        return remove(Wrappers.<FundProjectAmountDetail>lambdaQuery()
                .eq(FundProjectAmountDetail::getFundProjectId, baseId));
    }

    @Override
    public Map<Integer, List<FundProjectAmountDetail>> getMapByBaseId(Long baseId) {
        return list(Wrappers.<FundProjectAmountDetail>lambdaQuery()
                .eq(FundProjectAmountDetail::getFundProjectId, baseId)
                .orderByAsc(FundProjectAmountDetail::getOrderNumber))
                .stream().collect(Collectors.groupingBy(FundProjectAmountDetail::getAmountType));
    }

    @Override
    public Map<String, List<FundProjectAmountDetail>> getMapByBaseIds(List<Long> baseIds) {
        return list(Wrappers.<FundProjectAmountDetail>lambdaQuery()
                .in(FundProjectAmountDetail::getFundProjectId, baseIds)
                .orderByAsc(FundProjectAmountDetail::getOrderNumber))
                .stream().collect(Collectors.groupingBy(fundProjectAmountDetail ->
                        fundProjectAmountDetail.getFundProjectId() + StringPool.UNDERSCORE + fundProjectAmountDetail.getAmountType()));
    }
}
